# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

source 'https://git.oschina.net/lgjM/ljgproject.git'
source 'https://github.com/CocoaPods/Specs.git'

target 'Common' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
use_frameworks!

pod 'AFNetworking'
pod 'SDWebImage'
pod 'MBProgressHUD'

def generate_modulemap(name, path)
    f = File.new(File.join("#{path}/module.modulemap"), "w+")
    module_name = "#{name}"
    while(module_name["+"])
        module_name["+"] = "_"
    end           
    f.puts("module XB#{module_name} {")
    f.puts("    umbrella header \"#{name}_umbrella.h\"")
    f.puts("    export *")
    f.puts("}")
end

def generate_umbrella(name, path) 
    f = File.new(File.join("#{path}/#{name}_umbrella.h"), "w+")
    f.puts("#import <Foundation/Foundation.h>")
    Dir.foreach(path) do |filename|
        if filename != "." and filename != ".."
            f.puts("#import \"#{filename}\"")
        end
    end
end

post_install do |installer|
    require "fileutils"
    headers_path = "#{Dir::pwd}/Pods/Headers/Public/"

    installer.pods_project.targets.each do |target|
        target_header_path = "#{headers_path}#{target.product_name}"
        if File.exist?(target_header_path)
            filename = target.product_name
            if filename != "." and filename != ".."
                generate_umbrella(filename, target_header_path)
                generate_modulemap(filename, target_header_path)
            end
        end
    end
end


end
